<?php

/**
 * Louder Cache
 *
 * LICENSE
 *
 * This source file is subject to the New BSD License that is bundled
 * with this package in the file docs/LICENSE.txt.
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to info@loudertechnology.com so we can send you a copy immediately.
 *
 * @category Louder
 * @package CacheFactory
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */

/**
 * Factory de CacheReferences
 *
 * @category Louder
 * @package CacheFactory
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */
class CacheFactory {

	/**
	 * Configuracion del cache
	 *
	 * @var CacheConfiguration
	 */
	private $_configuration;

	/**
	 * Constructor de CacheFactory
	 *
	 * @param CacheConfiguration $configuration
	 */
	public function __construct(CacheConfiguration $configuration=null){
		if($configuration!=null){
			$this->_configuration = $configuration;
		}
	}

	/**
	 * Crea una CacheReference con la configuracion establecida
	 *
	 * @param CacheConfiguration $configuration
	 */
	public function createCache(CacheConfiguration $configuration=null){
		if($configuration==null&&$this->_configuration==null){
			throw new CacheFactoryException("Debe definir una configuración para crear el cache");
		}
		if($configuration!=null){
			$this->_configuration = $configuration;
		}
		return new CacheReference($this->_configuration);
	}

}
